programming4us
           
 
 
Programming

CSS for Mobile Browsers : Where to Insert the CSS (part 1) - Media Filtering

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/12/2010 3:29:42 PM
The first question to answer is: where should we tell the browser what styles to apply? We have many options:
  • <style> tags inside the XHTML or HTML markup

  • External stylesheets as .css files

  • style attributes inside the tags

The third option might seem like the most efficient approach, but it is not the best one. That said, there are times when it is useful.

<input type="text" name="name" style="-wap-input-format: A*a" />


Warning:

On BlackBerry devices running Device Software 4.5 or earlier, stylesheets can be disabled from the browser or from a corporate policy.


A fourth option (a new way of including an external stylesheet) is specified in the WAP CSS standard, but it is not implemented and not recommended as it offers no advantages. It looks like this:

<?xml-stylesheet href="style.css" media="handheld" type="text/css" ?>

If the website you are creating is a one-page document (a widget, an Ajax mobile application, or just a simple mobile document), it will be faster to include the CSS in the <style> XHTML tag to avoid a request and a rendering delay. The other ideal situation for this technique is if your home page is very different from the other pages in your site. Otherwise, odds are good that external stylesheets will help you manage your site more efficiently.

1. Media Filtering

Is one CSS stylesheet adequate for all devices? Maybe. The first factor to consider is whether we are working on a desktop XHTML site or a mobile-specific one.

1.1. Desktop websites

If we decide to use only one XHTML site for both desktop and mobile devices, our only option for changing the design and layout is the CSS file. This situation is a good fit for the media attribute.

The CSS standard allows us to define more than one stylesheet for the same document, taking into account the possibility of a site being rendered on different types of media. The most used values for the media attribute are screen (for desktops), print (to be applied when the user prints the document), and handheld (for… yes, mobile devices). There are also other values, like tv and braille, but no browsers currently support these.

Great! We’ve found the solution. We can just define two stylesheets, one for screen and one for handheld, and all our problems will be solved. The two stylesheets can define different properties for the same elements, and we can even use display: none to prevent some elements from being shown on mobile devices:

<link rel="stylesheet" type="text/css" media="screen" href="desktop.css" />
<link rel="stylesheet" type="text/css" media="handheld" href="mobile.css" />


However, this “ideal” situation becomes hell when we test it. Many modern mobile browsers rely on screen stylesheets because they can render any desktop website. And other browsers use screen when they think it is a desktop website and use handheld when they think it is a mobile website, depending on the DOCTYPE, a meta tag, or the user’s view preferences.


Warning:

To further complicate the situation, some mobile browsers (such as Mobile Internet Explorer) use media="handheld" if it is the only value defined, but use media="screen" by default if both are defined. The hack is to define media="Screen", with an uppercase S; this causes Mobile IE to use the handheld option when both are defined.


Table 1 shows the media values selected by the different mobile browsers when both screen and handheld options are defined in the document. Clearly, we can’t rely on the media="handheld" attribute!

Table 1. CSS media compatibility table
Browser/platformMedia used
Safariscreen
Android browserscreen
Symbian/S60screen
Nokia Series 40screen in 6th edition Both (no media understanding) before 6th edition
webOSscreen
BlackBerryscreen (handheld if meta available)
NetFronthandheld
Openwave (Myriad)handheld
Internet Explorerscreen
Motorola Internet Browserhandheld
Opera Mobilescreen
Opera Miniscreen


Other -----------------
- Developing an SEO-Friendly Website : Keyword Targeting (part 4)
- Developing an SEO-Friendly Website : Keyword Targeting (part 3)
- Developing an SEO-Friendly Website : Keyword Targeting (part 2)
- Developing an SEO-Friendly Website : Keyword Targeting (part 1) - Title Tags
- The Art of SEO : Optimization of Domain Names/URLs
- Cloud Security and Privacy : Regulatory/External Compliance (part 2)
- Cloud Security and Privacy : Regulatory/External Compliance (part 1)
- Developing an SEO-Friendly Website : Root Domains, Subdomains, and Microsites (part 2)
- Developing an SEO-Friendly Website : Root Domains, Subdomains, and Microsites (part 1)
- Parallel Programming with Microsoft .Net : Parallel Aggregation - An Example
- Parallel Programming with Microsoft .Net : Parallel Aggregation - The Basics
- Developing an SEO-Friendly Website : Creating an Optimal Information Architecture (part 4)
- Developing an SEO-Friendly Website : Creating an Optimal Information Architecture (part 3)
- Developing an SEO-Friendly Website : Creating an Optimal Information Architecture (part 2)
- Developing an SEO-Friendly Website : Creating an Optimal Information Architecture (part 1)
- Cloud Security and Privacy : Governance, Risk, and Compliance (GRC)
- Cloud Security and Privacy : Internal Policy Compliance
- jQuery 1.3 : Improving a basic form (part 8) - Checkbox manipulation
- jQuery 1.3 : Improving a basic form (part 7)
- jQuery 1.3 : Improving a basic form (part 6)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us